/*
 * @Author:
 * @Author:
 * @Date:
 * @lastModify
 * +----------------------------------------------------------------------
 * | WeAdmin 表格table中多个删除等操作公用js
 * | 有改用时直接复制到对应页面也不影响使用
 * +----------------------------------------------------------------------
 */
layui.extend({
	admin: '{/}/static/back/js/admin'
});
layui.use(['form', 'jquery','element'], function() {
	var form = layui.form,
		$ = layui.jquery,
        element = layui.element;

      //自定义验证规则
      form.verify({
          username: function(value){ //value：表单的值、
            if(!new RegExp("^[a-zA-Z][a-zA-Z0-9_]{4,15}$").test(value)){
              return '用户名须已字母开头，允许5-16位字符，允许字母数字下划线';
            }
          }
          ,password: [/(.+){6,12}$/, '密码必须6到12位']

      });


      //监听提交
      form.on('submit(subform)',function(data){

       //验证账号信息
            $.ajax({
                async: false,
                data: {
                    username: $('#username').val()
                    ,password:$('#password').val()
                },
                dataType: 'json',
                success: function(result) {
                    console.log(result)
                    if (result.code==1) {
                        layer.msg('登陆成功', {time: 1000, icon:6,offset: '20px',anim: 6},function(){
                            location.href = result.href
                        });
                    }
                    if(result.code == 0){
                        layer.msg('用户名或密码有误，请检查后登录', {time: 1000, icon:5,offset: '20px',anim: 6});
                        return false;
                    }
                    if(result.code == -1){
                        layer.msg('数据不正确或未知错误', {time: 1000, icon:2,offset: '20px',anim: 6});
                        return false;
                    }
                },
                error:function(){
                    layer.msg('数据不正确或未知错误', {time: 1000, icon:2,offset: '20px',anim: 6});
                    return false;
                },
                url: $('#path').val()
            });

       });

});
